import ChatUI from "../game/chat/ChatUI";
import GameUI from "../game/GameUI";
import BubbleUI from "../game/home/BubbleUI";
import HomeUI from "../game/home/HomeUI";
import HospitalUI from "../game/hospital/HospitalUI";
import StoreUI from "../game/store/StoreUI";
import TownUI from "../game/town/TownUI";
import { SceneGame } from "../SceneGame";
import GameUtil from "../Util/GameUtil";
import StorageUtil from "../Util/StorageUtil";
import { ESkeIndex } from "./Enum";

/** 对话数据 */
export interface ISayConfig {
    id: number;
    type: ETalkType;
    show?: EShowView[];
    hand?: EHandType;
    clicks?: string[];
    chatId?: number;
    isGroup?: boolean;
    talkName?: string;
    name?: string;
    desc?: string;
    audio?: string;
    nextId?: number;
    isComplete?: boolean;
    skeIndex?: ESkeIndex;
    isSay?: boolean;
    url?: string;
}

export enum EShowView {
    Null,
    HomeUI,
    TownUI,
    GameUI,
    ChatUI,
    StoreUI,
    HospitalUI,
}

export enum EHandType {
    Task,
    Come,
    // Repair,
    Nitpick,    // 功法
}

export enum ETalkType {
    /** 用来衔接剧情 */
    Link,
    /** 微信聊天框 */
    Chat,
    /** 气泡 */
    Bubble,
    /** 点击触发 */
    Click,
}

export class TalkModule {
    public static readonly STORY: number = -1;              // 故事前情

    public static readonly OPEN_CHAT: number = 10101;       // 开启聊天
    public static readonly OPEN_MINE: number = 10203;       // 开启矿山
    public static readonly OPEN_MARKET: number = 10304;     // 开启地摊
    public static readonly OPEN_NITPICK: number = 10411;    // 开启功法
    public static readonly OPEN_HOSPITAL: number = 10608;   // 开启中医馆
    public static readonly OPEN_STORE: number = 11008;      // 开启小卖店

    public static readonly COLLECT_TIEBAN: number = 10204;  // 收集动物符咒
    public static readonly COLLECT_ANIMAL: number = 10510;  // 收集动物符咒
    public static readonly COLLECT_FIVE: number = 11001;    // 收集五行珠

    public static readonly GUER_TALK3_END: number = 123;  // 顾浩第三段聊天结束

    //-------------------------------------------前情剧情----------------------------------
    private static storyConfigs: ISayConfig[] = [
        {
            id: 1,
            type: ETalkType.Bubble,
            name: "富商",
            desc: "废物！敢害你林姨受伤，给我滚出顾家。",
            audio: "废物！敢害你林姨",
            skeIndex: ESkeIndex.FuHao,
            isComplete: false
        },
        {
            id: 2,
            type: ETalkType.Bubble,
            name: "情人",
            desc: "远东，我跟云泽说了，我和浩浩是不会跟他争家产的，可他…",
            audio: "远东，我跟云泽",
            isComplete: false,
            nextId: 8
        },
        {
            id: 3,
            type: ETalkType.Bubble,
            name: "顾云泽",
            desc: "爸！是她害的妈哮喘发作，而且我根本没碰到她。",
            audio: "爸！是她害的",
            skeIndex: ESkeIndex.GuYunZe,
            isSay: true,
            isComplete: false
        },
        {
            id: 8,
            type: ETalkType.Bubble,
            name: "富商",
            desc: "我顾家容不下你们，以后你们跟我顾家两不相干！",
            audio: "我顾家容不下你们",
            skeIndex: ESkeIndex.FuHao,
            isComplete: false,
        },


        {
            id: 101,
            type: ETalkType.Bubble,
            name: "顾浩",
            desc: "顾云泽，脱离了顾家，顾家的东西也别想带走。",
            audio: "顾云泽，脱离了顾家",
            isComplete: false,
        },
        {
            id: 102,
            type: ETalkType.Bubble,
            name: "顾母",
            desc: "云泽，是妈妈不好，害的你被牵连。",
            audio: "云泽，是妈妈",
            isComplete: false,
            // nextId: 13,
        },
        {
            id: 103,
            type: ETalkType.Bubble,
            name: "顾云泽",
            desc: "妈！我会带你重回豪门，夺回顾家。",
            audio: "妈！我会带你",
            isComplete: false,
        },
    ];
    //---------------------------------------------END------------------------------------


    //-------------------------------------------对话聊天----------------------------------
    private static normalSayConfig: ISayConfig[] = [
        // 逐出豪门
        // 任务1
        { id: 10001, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾母', desc: '儿子，是妈妈连累了你。', audio: "儿子，是妈妈连累了你" },
        { id: 10002, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '妈，没了顾家，我照样能带你过上好日子。', audio: "妈，没了顾家" },
        { id: 10003, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾母', desc: '但那可是顾家，他不会让你我如意的。', audio: "但那可是顾家" },
        // TODO 接个顾母咳嗽
        { id: 10004, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '妈，别说了，我打扫一下屋子，你先休息。', audio: "妈，别说了" },
        { id: 10005, type: ETalkType.Link, show: [EShowView.GameUI] },

        // 任务2
        { id: 10101, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '你一个废物也想跟我争家产，我不过略施小计，你和那个老太婆就被赶出去了。', nextId: 10102 },
        { id: 10102, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '闭上你的臭嘴，你这么说就不怕我告诉爸吗？', nextId: 10103 },
        { id: 10103, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '你可以试试，看爸信我还是信你。', nextId: 10104 },
        { id: 10104, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '我会向爸证明，离了顾家，我也能爬到京都首富的位置。', nextId: 10105 },
        { id: 10105, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '真是可笑!如果我没猜错的话，你们现在住哪都是个问题吧?!哈哈哈哈哈哈哈。', nextId: 10106 },
        { id: 10106, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '可恶，你等着瞧!' },

        // 修墙对话开始
        { id: 10201, type: ETalkType.Bubble, show: [EShowView.HomeUI, EShowView.GameUI], name: '顾云泽', desc: '内心: 他说的没错，眼下我还先把屋子修好吧。' },
        { id: 10202, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '妈，我想把房顶修一下，你知道在哪能找到材料吗？', audio: "妈，我想把房顶修一下" },
        { id: 10203, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾母', desc: '你要材料的话，去矿山那边找找看吧。', audio: "你要材料的话" },
        { id: 10204, type: ETalkType.Link, show: [EShowView.GameUI] },

        // 任务3
        { id: 10301, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾母', desc: '儿子，要在这安家总得有启动基金，妈还有些首饰你拿去卖了吧。', audio: "妈还有些首饰" },
        { id: 10302, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '妈，那是姥姥给你的，不能卖啊。', audio: "妈，那是姥姥给你的" },
        { id: 10303, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾母', desc: '我们总要生活，等你赚钱了再买也来得及。', audio: "我们总要生活" },
        { id: 10304, type: ETalkType.Link, show: [EShowView.GameUI] },

        // 弹窗后触发
        { id: 10401, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '小仙君!我等了你这么久，你总算来了。', audio: "小仙君，我等了你这么久" },
        { id: 10402, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '老头，什么小仙君?你认错人了吧。', audio: "老头，什么小仙君" },
        { id: 10403, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '你跟你爹长得这么相像，我怎么会认错呢。', audio: "你跟你爹长得这么相像" },
        { id: 10404, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '绝对是你认错了，我和我爹长得一点都不像。', audio: "绝对是你认错了" },
        { id: 10405, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '那不是你亲爹。', audio: "那不是你亲爹" },
        { id: 10406, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '我爹不是我亲爹，那谁是我爹?难不成我爹是个神仙?', audio: "我爹不是我亲爹" },
        { id: 10407, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '是神仙，还是个大神仙。你爹20年前将你托付于我和刘琳，恐怕等的就是今天。', audio: "是神仙，还是个大神仙" },
        { id: 10408, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '你为什么知道我妈的名字? 那你知不知道，我妈宁愿来这里定居，也不回老家，到底是为什么?', audio: "你为什么知道我妈的名字" },
        { id: 10409, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '现在还不是让你知道的时候，这本淬体功法交于你，你要是碰到什么难题，就来此地寻我吧。', audio: "现在还不是让你知道的时候" },
        { id: 10410, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '这矿村的谜团越来越多了，算了，先想想怎么立足才是最实际的。', audio: "这矿村的谜团越来越多了" },
        { id: 10411, type: ETalkType.Link, show: [EShowView.GameUI] },

        // 重病医治
        { id: 10500, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '谢谢你照顾我妈。', audio: "谢谢你照顾我妈" },
        { id: 10501, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '林瑶', desc: '都是邻居，不足挂齿，我叫林瑶，在矿村做点小生意。', audio: "都是邻居" },
        { id: 10502, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '我叫顾云泽，对矿村不熟悉的地方，恐怕还要多麻烦你，不过，你有需要也尽管吩咐我就行。', audio: "我叫顾云泽" },
        { id: 10503, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '林瑶', desc: '那我就不客气了，话说回来，伯母的病，可不能再拖下去了，要尽快医治。', audio: "那我就不客气了" },
        { id: 10504, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '我妈这是老毛病了。求医多年都没能根治。', audio: "我妈这是老毛病了" },
        { id: 10505, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '林瑶', desc: '别灰心，御康馆的刘神医应该有办法，就是诊金不低。', audio: "别灰心" },
        { id: 10506, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '实不相瞒，我现在口袋空空，恐怕付不起诊金。', audio: "实不相瞒" },
        { id: 10507, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '林瑶', desc: '你要赚钱的话，我能帮你。', audio: "你要赚钱的话" },
        { id: 10508, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '顾云泽', desc: '真的嘛，大恩不言谢，算我欠你一个人情。', audio: "真的嘛，大恩不言谢" },
        { id: 10509, type: ETalkType.Bubble, show: [EShowView.HomeUI], name: '林瑶', desc: '我在矿村收些奇珍异宝，矿山那里就能找到。只要你能帮我找来，价格不是问题。', audio: "我在矿村收些奇珍异宝" },
        { id: 10510, type: ETalkType.Link, show: [EShowView.GameUI] },

        { id: 10551, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '林瑶', desc: '货我就先收下了，以后我也会不定期收些稀有货，你要是能搞到就来镇子上找我吧，报酬可不低哦。', audio: "报酬可不低哦" },
        { id: 10552, type: ETalkType.Link, show: [EShowView.GameUI, EShowView.TownUI] },

        // 任务五
        { id: 10601, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '那老不死的旧病应该是又复发了吧。', nextId: 10602 },
        { id: 10602, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '关你什么事！', nextId: 10603 },
        { id: 10603, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '我这不是来帮你了嘛，你来顾家给小爷我连磕三个响头，我就发发慈悲赏你几个子怎么样？', nextId: 10604 },
        { id: 10604, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '顾二！闭上你的嘴，我的事不用你操心。' },

        { id: 10605, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '刘神医', desc: '你就是小瑶说的那个后生？', nextId: 10606 },
        { id: 10606, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '顾云泽', desc: '刘神医？是我，我想求您救治我妈妈。', nextId: 10607 },
        { id: 10607, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '刘神医', desc: '来御康馆吧，我在这里等你。' },
        { id: 10608, type: ETalkType.Link, show: [EShowView.GameUI, EShowView.TownUI] },

        // 中医馆
        { id: 10706, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '刘神医', desc: '没想到，居然会这么相像，难不成你真是那个人的孩子。', audio: "没想到，居然会这么相像" },
        { id: 10707, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '顾云泽', desc: '又是那个人，你们矿村的人究竟再打什么哑谜。', audio: "又是那个人" },
        { id: 10708, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '刘神医', desc: '你还不知道?离约定还有些日子，你还是先不知道的好。', audio: "你还不知道" },
        { id: 10709, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '顾云泽', desc: '什么跟什么啊，刘神医，我是来找你帮我妈医治的。', audio: "什么跟什么啊" },
        { id: 10710, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '刘神医', desc: '我是不会给你妈医治的。', audio: "我是不会给你妈医治的" },
        { id: 10711, type: ETalkType.Link, show: [EShowView.GameUI] },
        // 出现冰封按钮

        { id: 10800, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '顾云泽', desc: '刘神医，我敬重你才会称您为神医，但你也不能拿我母亲的性命作玩笑。', audio: "我敬重你才会称您为神医" },
        { id: 10801, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '刘神医', desc: '我不会给你母亲医治，但我可以教给你，由你来给你母亲医治。', audio: "我不会给你母亲医治" },
        { id: 10802, type: ETalkType.Link, show: [EShowView.GameUI] },
        { id: 10805, type: ETalkType.Bubble, show: [EShowView.HospitalUI], name: '刘神医', desc: '好小子！以后你就是我御康馆的关门弟子了。不过要想替你母亲诊治，还是要先从学徒做起。', audio: "关门弟子" },
        { id: 10806, type: ETalkType.Link, show: [EShowView.GameUI] },
        
        // 任务七
        { id: 10900, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '刘神医', desc: '好小子，没想到你能这么快完成我留给你的考验。', nextId: 10901 },
        { id: 10901, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '顾云泽', desc: '还是多亏了神医你教导有方。', nextId: 10902 },
        { id: 10902, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '刘神医', desc: '行了！你在我这就别贫嘴了。赶紧回家来吧，我教你如何为你母亲医治。' },

        // 任务八
        { id: 10906, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '林瑶', desc: '恭喜恭喜，伯母的病情总算稳定下来了。', nextId: 10907 },
        { id: 10907, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '顾云泽', desc: '是我要感谢你才对，要不是你，刘神医也不会收我为徒。', nextId: 10908 },
        { id: 10908, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '林瑶', desc: '我没帮上什么忙，应该是刘神医见你与那人长得一样，才起了收徒的想法。', nextId: 10909 },
        { id: 10909, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '顾云泽', desc: '上次那个疯老头也说我很像一个人，连你也这么说，你们究竟在打什么谜语。', nextId: 11000 },
        { id: 11000, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '林瑶', desc: '等到了时间，你就会知道了，现在你要想的是怎么赚钱，新的货单给你发过去了，记得来村子里找我。' },

        // 任务九
        { id: 11006, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '林瑶', desc: '听说小卖店的老板想把店铺兑出去，你可要抓住这个机会。', nextId: 11007 },
        { id: 11007, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1003, isGroup: false, name: '顾云泽', desc: '这就去探一探，多谢瑶老板了。' },
        { id: 11008, type: ETalkType.Link, show: [EShowView.GameUI] },

        // 花大妈
        { id: 11101, type: ETalkType.Bubble, show: [EShowView.StoreUI], name: '花大妈', desc: '闭店了，要买东西明天再来。', audio: "闭店了" },
        { id: 11102, type: ETalkType.Bubble, show: [EShowView.StoreUI], name: '顾云泽', desc: '我是来盘下这间店铺的。', audio: "我是来盘下这间店铺的" },
        { id: 11103, type: ETalkType.Bubble, show: [EShowView.StoreUI], name: '花大妈', desc: '那你打算花多少钱？', audio: "那你打算花多少钱" },
        { id: 11104, type: ETalkType.Link, show: [EShowView.GameUI] },
        { id: 11105, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '花大妈', desc: '没想到你小子, 居然还有两下子。那就按照你说的500万。', audio: "没想到你小子" },

        // 小卖店
        { id: 11201, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '你个废物，居然真的在村里做上生意了，不过就你那土气的样子也就只能做个小卖店了', nextId: 11202 },
        { id: 11202, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '顾二，别得意的太早，早晚我会带着我妈把你们踹出顾家的。', nextId: 11203 },
        { id: 11203, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '就凭你？一个小卖店就能把你绑死，拿什么壮大产业跟顾家斗。' },



        // TODO
        // TODO
        // TODO 目前版本卡在这里，后续等更新
        // 林瑶帮忙
        { id: 11206, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '顾二虽然说的话欠揍，但我也确实该招一位店员了。' },
        { id: 11207, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '林瑶', desc: '听说你准备招聘一位店员？我过来帮忙吧~' },
        { id: 11208, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '林大小姐出马，那当然是求之不得。' },

        // TODO 回家招人 任务10


        // 揭露真相---绑架
        { id: 11301, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '光顾着招聘美女店员，怕不是连重要的人丢了都没察觉。', nextId: 11302 },
        { id: 11302, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '你把我妈怎么了！', nextId: 11303 },
        { id: 11303, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '只不过想请她喝喝茶，顺便问一下她把顾家至宝藏哪里去了', nextId: 11304 },
        { id: 11304, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾云泽', desc: '什么顾家至宝，我和我妈从顾家出来什么都没带。你们快把我妈放了', nextId: 11305 },
        { id: 11305, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1001, isGroup: false, name: '顾浩', desc: '我说你有你就有，限你七天内将顾家至宝还回来。七天之后，我可不保证你妈的安危' },

        // 点击触发
        { id: 11401, type: ETalkType.Click, name: '顾云泽', desc: '来的很块，像是有计划一样' },
        { id: 11402, type: ETalkType.Click, name: '顾云泽', desc: '他们在翻找什么东西' },
        { id: 11403, type: ETalkType.Click, name: '顾云泽', desc: '走的很匆忙，可能有目击者发现了他们' },
        { id: 11404, type: ETalkType.Click, name: '顾云泽', desc: '' },           // 点击纸条放大
        { id: 11405, type: ETalkType.Click, name: '顾云泽', desc: '为什么照片里的人跟我长得一模一样？' },

        // 跳出提示手左滑照片，按照提示左滑照片，照片翻到背面。出现做旧内容地图。出现文字框（看样子这是矿村的地图，但为什么这么旧？）
        // 跳出对话框（不管如何，先从这个地方下手准没错）

        // 寻找照片碎片
        { id: 11501, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '少年，我看你印堂发黑，眉宇紧锁，恐有大事发生，破财之兆啊！' },
        { id: 11502, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '老头，我现在没时间听你瞎扯，我在赶时间' },
        { id: 11503, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '老乞丐', desc: '你我有缘，给你指条明路，天地人三才，我来当这第一才。去矿村西北方寻属金之地，就能找到你想要的东西。' },
        { id: 11504, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '老头！走的好快啊。不过，他是怎么知道我要去满运乾坤的？' },

        // 开启刮刮乐

        // 林瑶对话
        { id: 11601, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '林瑶', desc: '你好慢啊，我都等你好久了。' },
        { id: 11602, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '怎么？林大小姐找我有事？' },
        { id: 11603, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '林瑶', desc: '没事就不能找你了？呐，我是来给你找个的' },
        { id: 11604, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '你怎么会有这个？你又怎么知道我在找它'},
        { id: 11605, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '林瑶', desc: '这是我爷爷交给我保存的，他说到了时间，我自然知道该怎么做。现在就是那个时间' },
        { id: 11606, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '顾云泽', desc: '你爷爷？这跟他又有什么关系，还有你知道为什么照片上的人跟我长的一样吗？' },
        { id: 11607, type: ETalkType.Bubble, show: [EShowView.TownUI], name: '林瑶', desc: '这个我就不知道了，去吧刘叔在御康馆等你' },

        { id: 11701, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '刘神医', desc: '你总算来了', nextId: 11702 },
        { id: 11702, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '顾云泽', desc: '刘老，为什么你们都在说一些没头没尾的话，到底发生了什么', nextId: 11703 },
        { id: 11703, type: ETalkType.Chat, show: [EShowView.GameUI], chatId: 1002, isGroup: false, name: '刘神医', desc: '事实的真相，只能你自己去找了' },

        // 跳出文字提示（碎片已放入背包）。
        // 跳出成图 — 照片碎片合成一张完整的图，跳出对话框（顾云泽：这个人究竟是谁，为什么还有个孩子）回到乡镇界面，
        // 手机提示UI，进入手机界面，（顾二：没想到还真的被你找到了，带着照片来顾家换你妈吧。）
    ];

    public static getSayConfigById(id: number) {
        const talkData = StorageUtil.instance.getTalkData();
        if (talkData.id < 1) {
            // 前情对话
            const data = this.storyConfigs.find((o) => o.id === id);
            return data;
        } else {
            // 非前情对话
            const data = this.normalSayConfig.find((o) => o.id === id);
            return data;
        }
    }

    public static getChatConfigByType(type: ETalkType) {
        const talkData = StorageUtil.instance.getGameData().talkData;
        const datas = this.normalSayConfig.filter((o) => o.type === type && o.id <= talkData.id);
        return datas;
    }

    public static saveTalkData() {
        const talkData = StorageUtil.instance.getTalkData();
        if (talkData.id > -1) { // 前情不存数据
            talkData.id++;
            console.log("BubbleUI.refresh()===>储存talkId:", talkData.id);
        }

        this.updateCheck();
    }

    private static configs() {
        const configs: { show: EShowView, ins: any }[] = [
            { show: null, ins: null },
            { show: EShowView.HomeUI, ins: HomeUI.instance },
            { show: EShowView.TownUI, ins: TownUI.instance },
            { show: EShowView.GameUI, ins: GameUI.instance },
            { show: EShowView.ChatUI, ins: ChatUI.instance },
            { show: EShowView.StoreUI, ins: StoreUI.instance },
            { show: EShowView.HospitalUI, ins: HospitalUI.instance },
        ]
        return configs;
    }

    private static isPopView(show: EShowView) {
        const isView = show === EShowView.ChatUI || show === EShowView.StoreUI || show === EShowView.HospitalUI;
        return isView;
    }

    public static updateAllCheck() {
        const configs = this.configs();
        configs.forEach((o) => {
            if (o.ins?.node?.active) o.ins.check();
        });
    }

    public static async updateCheck() {
        const configs = this.configs();
        const talkData = StorageUtil.instance.getTalkData();
        if (talkData.id > 11203) { // TODO 流程卡在11203
            return;
        }

        const talk = this.getSayConfigById(talkData.id);
        if (talk && talk.show) {
            // 根据配置更新页面
            for (let i = 0; i < talk.show.length; i++) {
                const config = configs.find((o) => o.show === talk.show[i]);
                // 延时0.1s(防止脚本还没加载的情况)
                await GameUtil.sleep(100);
                if (config && config.ins && config?.ins?.node?.active) {
                    console.log(`TalkMoudle.updateCheck()===>${config.ins.name}...check`);
                    config.ins.check(talk);

                    switch (talk.type) {
                        case ETalkType.Bubble:
                            {
                                this.updateBubble();
                            }
                            break;
                        case ETalkType.Chat:
                            {
                                // AudioManager.instance.playSound('信息提示');
                            }
                            break;
                        case ETalkType.Link:
                            {
                                this.updateAllCheck();
                            }
                            break;
                    }
                }
            }
        }
    }

    private static updateBubble(callback?: Function) {
        const talkData = StorageUtil.instance.getTalkData();
        if (talkData.id > 0) {
            // 从对话配置取
            const config: ISayConfig = TalkModule.getSayConfigById(talkData.id);
            if (config && config.type === ETalkType.Bubble) {
                const bubble = SceneGame.instance.bubble;
                const comp = bubble.getComponent(BubbleUI);
                comp.refresh(config, callback);
            }
        }
    }

    /**
     * 前情气泡用这个
     * @param id 
     * @param callback 
     */
    public static updateStoryBubble(id: number, callback?: Function) {
        // 从前情取数据
        const talkData: ISayConfig = TalkModule.getSayConfigById(id);
        if (talkData) {
            const bubble = SceneGame.instance.bubble;
            const comp = bubble.getComponent(BubbleUI);
            comp.refresh(talkData, callback);
        }
        console.log("LayerGame.updateBubble()===>talkData:", talkData);
    }
}